import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 存储token
    Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
    product:{}
  },
  mutations: {
    //注册处理函数，在login组件的login方法上使用this.$store.commit('login',data);
    login(state, user) {
      state.Authorization = user;
      localStorage.setItem('Authorization', user)
    },
    SET_NEW_DATA(state,{product_id,product_barcode,image,product_name,product_price,num}){
      state.product.id=product_id;
      state.product.product_barcode=product_barcode;
      state.product.product_name=product_name;
      state.product.product_price=product_price;
      state.product.num=num;
      state.product.image=image;
    },
    SET_CLEAR_DATA(state,data){
      state.id=data;
    }
  },
  actions: {
    addSetting({commit}){
      commit('SET_NEW_DATA',{product_id,product_barcode,image,product_name,product_price,num});
    }
  },
  modules: {}
})